package com.summerbird.mallchat.common.user.service.adapter;

import com.summerbird.mallchat.common.chat.domain.entity.Contact;
import com.summerbird.mallchat.common.chat.domain.entity.GroupMember;
import com.summerbird.mallchat.common.chat.domain.entity.Room;
import com.summerbird.mallchat.common.chat.domain.enums.GroupRoleEnum;
import com.summerbird.mallchat.common.chat.domain.enums.HotFlagEnum;
import com.summerbird.mallchat.common.chat.domain.enums.RoomTypeEnum;
import com.summerbird.mallchat.common.chat.domain.vo.response.ChatMessageReadResp;

import java.util.List;
import java.util.stream.Collectors;

public class RoomAdapter {
    public static Room buildRoom(RoomTypeEnum typeEnum) {
        Room room = new Room();
        room.setType(typeEnum.getType());
        room.setHotFlag(HotFlagEnum.NOT.getType());
        return room;
    }

    public static List<ChatMessageReadResp> buildReadResp(List<Contact> list) {
        return list.stream().map(contact -> {
            ChatMessageReadResp resp = new ChatMessageReadResp();
            resp.setUid(contact.getUid());
            return resp;
        }).collect(Collectors.toList());
    }

    public static List<GroupMember> buildGroupMemberBatch(Long groupId, List<Long> uidList) {
        return uidList.stream().distinct().map(uid -> {
            GroupMember member = new GroupMember();
            member.setGroupId(groupId);
            member.setUid(uid);
            member.setRole(GroupRoleEnum.MEMBER.getType());
            return member;
        }).collect(Collectors.toList());
    }
}
